#!/usr/env/bin python
# -*- coding: utf-8 -*-

# @Time    : 2020-10-21 10:07 上午
# @Author  : yangdy
# @File    : 2020-10-21.925.长按键入
# @Software: PyCharmCE
class Solution:
    def isLongPressedName(self, name: str, typed: str) -> bool:
        name_c, typed_c = [], []

        def count(ss, cc):
            if not ss:
                cc = []
                return
            cc.append([ss[0], 1])
            for i in range(1, len(ss)):
                if ss[i] == ss[i - 1]:
                    cc[-1][1] += 1
                else:
                    cc.append([ss[i], 1])

        count(name, name_c)
        count(typed, typed_c)
        if len(name_c) != len(typed_c):
            return False
        for i in range(len(name_c)):
            if name_c[i][0] != typed_c[i][0] or name_c[i][1] > typed_c[i][1]:
                return False
        return True
